package loja;
import java.util.LinkedList;

import dbconnection.BaseDados;

public class GestorCliente {

	/***********************************************************
	 *Gestor Cliente (or client manager) Class
	 ***********************************************************/

	private GestorStock gestor_stock = null;
	private BaseDados base_dados = null;

	/**
	 * Create a new Gestor Cliente (or Client Manager) (constructor)
	 * @param base_dados
	 * @param gestor_stock
	 */
	public GestorCliente(BaseDados base_dados,GestorStock gestor_stock){
		this.base_dados = base_dados;
		this.gestor_stock=gestor_stock;

	}

	/***********************************************************
	 * Method used to get the client manager
	 * @return return gestor_stock
	 ***********************************************************/
	public GestorStock getGestorStock() {
		return gestor_stock;
	}

	/***********************************************************
	 * Method used to get the database
	 * @return return database
	 ***********************************************************/
	public BaseDados getBaseDadosCliente() {
		return base_dados;
	}

	/***********************************************************
	 * Method used to get the list of products
	 * @return return the list of products
	 ***********************************************************/	
	public LinkedList<Produto> getListaProdutos() {
		return base_dados.getProdutos();
	}
	/***********************************************************
	 * Method used to get the list of invoice
	 * @return return the list of invoices
	 ***********************************************************/
	public LinkedList<Factura> getListaFacturas() {
		return base_dados.getFacturas();
	}

	/***********************************************************
	 * Method used to get the list of clients
	 * @return return the list of clients
	 ***********************************************************/
	public LinkedList<Cliente> getListaClientes() {
		return base_dados.getClientes();
	}

	/***********************************************************
	 * Method used to add a new client at the list
	 * @param ac Receive a client to add
	 * @throws JaExisteException 
	 ***********************************************************/
	public void adicionarCliente(Cliente ac) throws JaExisteException{

		base_dados.adiciona(ac);
	}

	/***********************************************************
	 * Method used to remove a existent client at the list
	 * @param ac Receive a client to remove
	 ***********************************************************/
	public void removerCliente(Cliente rc){

		base_dados.retira(rc);

	}

	/***********************************************************
	 * Method used to search a client through an identifier
	 * @param numero_cliente Receive a client identifier
	 ***********************************************************/
	public Cliente pesquisarCliente(int numero_cliente){

		return base_dados.getCliente(numero_cliente);
	}

	/***********************************************************
	 * Method used verify if some cliente exists or not
	 * @param numero_cliente Receive a client identifier
	 * @return true if Cliente exists
	 ***********************************************************/
	public boolean existeCliente(int numero_cliente){

		for (Cliente rc: base_dados.getClientes()){

			if(rc.getNumeroCliente() == numero_cliente){

				return true;
			}
		}
		return false;

	}

	/***********************************************************
	 * Method used to push a Factura (or Invoice) from Database
	 * @param factura_corrente
	 ***********************************************************/
	public void retira(Factura factura_corrente) {
		base_dados.retira(factura_corrente);

	}

	/***********************************************************
	 * Method used to get the an invoice (or Factura)
	 * @return return the list of clients
	 ***********************************************************/
	public Factura getFactura(int numero) {
		return base_dados.getFactura(numero);
	}

	/***********************************************************
	 * Method used to add an invoice to the Database
	 * @param factura_corrente
	 ***********************************************************/
	public void adiciona(Factura factura_corrente) {

		try {
			base_dados.adiciona(factura_corrente);
		} catch (JaExisteException e) {
			e.printStackTrace();
		}
	}

	public Cliente getCliente(int id_cliente) {
		return base_dados.getCliente(id_cliente);
	}

	public boolean adiciona(Factura f, Cliente c) {
			return base_dados.adiciona(f, c);
	}
}
